package CuratorCtrl;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class EditFrame extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8916949487354856787L;
	private JPanel jPanel1;
	private JButton jButton1;
	private JTextField tfMem;
	private JLabel jLabel1;
	private JPanel jPanel4;
	private JPanel jPanel3;
	private Image theVM;
	private String theName;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				EditFrame inst = new EditFrame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public EditFrame() {
		
		super();
		initGUI();
	}

	public EditFrame(String name) {
		super();
		theName=name;
		try {
			theVM=Util.read_singleVM(name);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		initGUI();
	}
	private void initGUI() {
		try {
			//if(theVM==null)return;
			GridLayout thisLayout = new GridLayout(5, 2);
			thisLayout.setColumns(1);
			thisLayout.setHgap(5);
			thisLayout.setVgap(5);
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jPanel1 = new JPanel();
				BoxLayout jPanel1Layout = new BoxLayout(jPanel1, javax.swing.BoxLayout.X_AXIS);
				jPanel1.setLayout(jPanel1Layout);
				getContentPane().add(jPanel1);
				jPanel1.setPreferredSize(new java.awt.Dimension(400, 33));
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("     Memory");
					jLabel1.setPreferredSize(new java.awt.Dimension(167, 15));
				}
				{
					tfMem = new JTextField();
					jPanel1.add(tfMem);
					tfMem.setText(theVM.getMem()+"");
					tfMem.setPreferredSize(new java.awt.Dimension(221, 51));
				}
			}
			{
				jPanel3 = new JPanel();
				GridLayout jPanel3Layout = new GridLayout(1, 1);
				jPanel3.setLayout(jPanel3Layout);
				getContentPane().add(jPanel3);
				jPanel3Layout.setColumns(1);
				jPanel3Layout.setHgap(5);
				jPanel3Layout.setVgap(5);
				{
					jButton1 = new JButton();
					jPanel3.add(jButton1);
					jButton1.setText("Apply");
					jButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							try {
								jButton1ActionPerformed(evt);
							} catch (NumberFormatException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}
					});
				}
			}
			{
				jPanel4 = new JPanel();
				BoxLayout jPanel4Layout = new BoxLayout(jPanel4, javax.swing.BoxLayout.X_AXIS);
				jPanel4.setLayout(jPanel4Layout);
				getContentPane().add(jPanel4);
			}
			pack();
			this.setSize(400, 214);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private void jButton1ActionPerformed(ActionEvent evt) throws NumberFormatException, IOException {
		System.out.println("jButton1.actionPerformed, event="+evt);
		Util.change_mem(theName,Integer.parseInt(tfMem.getText()));
		//TODO add your code for jButton1.actionPerformed
		this.setVisible(false);
	}

}
